class Solution(object):
    def threeEqualParts(self, arr):
        count_1 = arr.count(1)
        if count_1 == 0:
            return [0, 2]
        if count_1 % 3:
            return [-1, -1]
        t = count_1 // 3
        houzhui_0 = 0
        n = len(arr)
        for i in range(n - 1, -1, -1):
            if arr[i] == 0:
                houzhui_0 += 1
            else:
                break
        index = 0
        now_t = 0
        now_houzhui = 0
        duandian = []
        while index < n:
            if arr[index] == 1:
                now_t += 1
            if arr[index] == 0:
                if now_t == t:
                    now_houzhui += 1
            if now_t == t and now_houzhui == houzhui_0:
                duandian.append(index)
                if len(duandian) == 2:
                    break
                now_t = 0
                now_houzhui = 0
            if now_t > t:
                return [-1, -1]
            index += 1
        flag = True
        ans1 = []
        for index in range(0, duandian[0] + 1):
            if arr[index] == 0:
                if not flag:
                    ans1.append(arr[index])
            else:
                flag = False
                ans1.append(arr[index])
        ans2 = []
        flag = True
        for index in range(duandian[0] + 1, duandian[1] + 1):
            if arr[index] == 0:
                if not flag:
                    ans2.append(arr[index])
            else:
                flag = False
                ans2.append(arr[index])
        ans3 = []
        flag = True
        for index in range(duandian[1] + 1, n):
            if arr[index] == 0:
                if not flag:
                    ans3.append(arr[index])
            else:
                flag = False
                ans3.append(arr[index])
        if ans1 == ans2 == ans3:
            return [duandian[0], duandian[1] + 1]
        else:
            return [-1, -1]
data = Solution()
arr = [1,0,1,0,1]
print(data.threeEqualParts(arr))